import { PageParams } from '@/api/model/pageParams';
import { request } from '@/utils/request';

const pageApi = async (params: PageParams) => {
  return request.post({
    url: '/dishes/page',
    data: params,
  });
};

const insertApi = async (data: any) => {
  return request.post({
    url: '/dishes/insert',
    data,
  });
};

const updateApi = async (data: any) => {
  return request.post({
    url: '/dishes/update',
    data,
  });
};

const deleteApi = async (id: string) => {
  return request.get({
    url: `/dishes/delete/${id}`,
  });
};

// 添加原料
const addMaterialsApi = async (data: any) => {
  return request.post({
    url: '/dishes/addMaterial',
    data,
  });
};
// 删除原料
const deleteMaterialsApi = async (id: number, materialId: number) => {
  return request.get({
    url: `/dishes/deleteMaterial/${id}/${materialId}`,
  });
};

// 添加/编辑步骤
const addStepsApi = async (data: any) => {
  return request.post({
    url: '/dishes/addSteps',
    data,
  });
};
// 删除再排序步骤
const sortStepsApi = async (data: object[]) => {
  return request.post({
    url: '/dishes/sortSteps',
    data,
  });
};

export { addMaterialsApi, addStepsApi, deleteApi, deleteMaterialsApi, insertApi, pageApi, sortStepsApi, updateApi };
